//
//  NetWorkingMangerFactory.m
//  YiJuZhangShou
//
//  Created by 冷悦 on 16/3/6.
//  Copyright © 2016年 Uranus. All rights reserved.
//

#import "NetworkingManagerFactory.h"
#import "TableRefreshFailureCallback.h"
#import "CollectionRefreshFailureCallback.h"

@implementation NetworkingManagerFactory

#pragma mark - Private
+ (NetworkingNormalManager *)generateCommonManager{
    NetworkingNormalManager *manager = [NetworkingNormalManager new];
    CommonFailureCallback *commonFailureCallback = [CommonFailureCallback new];
    manager.failureCallback = commonFailureCallback;
    return manager;
}

#pragma mark - Public
+ (NetworkingBaseManager *)generateNormalManager{
    NetworkingNormalManager *manager = [NetworkingManagerFactory generateCommonManager];
    NetworkingBaseInterceptor *interceptor = [NetworkingBaseInterceptor new];
    manager.baseInterceptor = interceptor;
    return manager;
}

+ (NetworkingBaseManager *)generateNormalManagerWithRefreshFailureCallBackWithTableView:(UITableView *)tableView{
    NetworkingNormalManager *manager = [NetworkingManagerFactory generateCommonManager];
    NetworkingBaseInterceptor *interceptor = [NetworkingBaseInterceptor new];
    TableRefreshFailureCallback *commonFailureCallback = [TableRefreshFailureCallback new];
    commonFailureCallback.tableView = tableView;
    manager.failureDelegate = commonFailureCallback;
    manager.baseInterceptor = interceptor;
    return manager;
}

+ (NetworkingBaseManager *)generateNormalManagerWithRefreshFailureCallBackWithCollectionView:(UICollectionView *)collectionView{
    NetworkingNormalManager *manager = [NetworkingManagerFactory generateCommonManager];
    NetworkingBaseInterceptor *interceptor = [NetworkingBaseInterceptor new];
    CollectionRefreshFailureCallback *commonFailureCallback = [CollectionRefreshFailureCallback new];
    commonFailureCallback.collectionView = collectionView;
    manager.failureDelegate = commonFailureCallback;
    manager.baseInterceptor = interceptor;
    return manager;
}

+ (NetworkingBaseManager *)generateResolveManager{
    NetworkingNormalManager *manager = [NetworkingManagerFactory generateCommonManager];
    NetworkingResolveInterceptor *interceptor = [NetworkingResolveInterceptor new];
    manager.baseInterceptor = interceptor;
    return manager;
}

+ (NetworkingAESManager *)generateAESManager:(NSString *)iv{
    NetworkingAESManager *manager = [NetworkingAESManager new];
    CommonFailureCallback *commonFailureCallback = [CommonFailureCallback new];
    manager.failureDelegate = commonFailureCallback;
    manager.iv = iv;
    NetworkingAESConfigInterceptor *interceptor = [NetworkingAESConfigInterceptor new];
    manager.baseInterceptor = interceptor;
    
    return manager;
}

+ (NetworkingBaseManager *)generateSHA256Manager{
    NetworkingNormalManager *manager = [NetworkingManagerFactory generateCommonManager];
    CommonFailureCallback *commonFailureCallback = [CommonFailureCallback new];
    manager.failureDelegate = commonFailureCallback;
    NetworkingSHA256ConfigInterceptor *interceptor = [NetworkingSHA256ConfigInterceptor new];
    manager.baseInterceptor = interceptor;
    
    return manager;
}

+ (NetworkingBaseManager *)generateSHA256ManagerWithRefreshFailureCallBackWithTableView:(UITableView *)tableView{
    NetworkingNormalManager *manager = [NetworkingManagerFactory generateCommonManager];
    TableRefreshFailureCallback *commonFailureCallback = [TableRefreshFailureCallback new];
    commonFailureCallback.tableView = tableView;
    manager.failureDelegate = commonFailureCallback;
    NetworkingSHA256ConfigInterceptor *interceptor = [NetworkingSHA256ConfigInterceptor new];
    manager.baseInterceptor = interceptor;
    return manager;
}

+ (NetworkingAESManager *)generateAESAndSHA256Manager:(NSString *)iv{
    NetworkingAESManager *manager = [NetworkingAESManager new];
    CommonFailureCallback *commonFailureCallback = [CommonFailureCallback new];
    manager.failureDelegate = commonFailureCallback;
    manager.iv = iv;
    NetworkingAESAndSHAConfigInterceptor *interceptor = [NetworkingAESAndSHAConfigInterceptor new];
    manager.baseInterceptor = interceptor;
    return manager;
}

@end
